<template>
  <div>
    <van-nav-bar title="首页"></van-nav-bar>
    <van-grid>
      <van-grid-item
        v-for="item in list"
        :key="item.dictValue"
        icon="photo-o"
        :text="item.dictLabel"
        :to="'/videoList?type='+ item.dictValue + '&title='+ item.dictLabel"
      />
    </van-grid>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { showLoadingToast } from "vant";
import { useDictStoreHook } from "@/store/modules/dict";

const list = ref([]);

const toast1 = showLoadingToast({
  message: "加载中...",
  forbidClick: true,
  duration: 0,
});

const onLoad = () => {
  // 获取数据
  toast1.open();
  // 获取字典
  useDictStoreHook()
    .loadDict("video_type")
    .then((res) => {
      list.value = res;
      toast1.close();
    })
    .catch((err) => {
      console.log("🚀 ~.then ~ err:", err);
      toast1.close();
    })
    .finally(() => {
      toast1.close();
    });
};

onLoad();
</script>